
import pygame, math, sys, random
#stuff 
class Robot(pygame.sprite.Sprite):
    def __init__(self, position, screenSize):
        self.images = []
        self.images += [pygame.image.load("rsc/Player/player.png")]
        self.frame = 0
        self.image = self.images[self.frame]
        self.rect = self.image.get_rect()
        self.place(position)
        self.radius = self.rect.width/2.5
        self.maxSpeed = 8
        self.x = position[0]
        self.realx = 0
        self.y = position[0]
        self.realy = 0
        self.scrollThreshold = 250
        self.scrolling = False
        self.damage = 5
        self.health = 100
        self.living = True
        self.didHit = False
        self.speed = [0, 0]
    
    def place(self, position):
        self.rect.center = position
        #print "I've moved to", position
    
    def distToPoint(self, pt):
        x1 = self.rect.center[0]
        x2 = pt[0]
        y1 = self.rect.center[1]
        y2 = pt[1]
        return math.sqrt(((x2-x1)**2)+((y2-y1)**2))
    
    def move(self):
        self.realx += self.speed[0]
        self.x += self.speed[0]
        if self.x >= self.screenWidth - self.scrollThreshold:
            self.x = self.screenWidth - self.scrollThreshold
            self.scrolling = True
        elif self.x <= self.scrollThreshold:
            self.x = self.scrollThreshold
            self.scrolling = True
        else:
            self.scrolling = False
        
        self.place([self.x, self.realy])
        
    def direction(self, dir):
        if dir == "up":
            self.speed[1] = -self.maxSpeed
        elif dir == "down":
            self.speed[1] = self.maxSpeed
        elif dir == "right":
            self.speed[0] = self.maxSpeed
        elif dir == "left":
            self.speed[0] = -self.maxSpeed
        
        elif dir == "stop up":
            self.speed[1] = 0
        elif dir == "stop down":
            self.speed[1] = 0
        elif dir == "stop right":
            self.speed[0] = 0
        elif dir == "stop left":
            self.speed[0] = 0
    
    def DinosaurCollide(self, other):
        if (self.rect.right > other.rect.left 
            and self.rect.left < other.rect.right):
            if (self.rect.bottom > other.rect.top and 
                self.rect.top < other.rect.bottom):
                if (self.distToPoint(other.rect.center)
                    < self.radius + other.radius): 
                        other.speed[0] = other.speed[0] * -1
                        other.speed[1] = other.speed[1] * -1
                   
    def update(*args):
        self = args[0]
        self.xOffset = args[1]
        self.didHit = False
        if not self.living:
            self.kill()
        self.move()
        self.wallCollide()
        self.DinosaurCollide()